package com.heima.media.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.heima.common.dto.PageResponseResult;
import com.heima.common.dto.ResponseResult;
import com.heima.media.dto.WmSensitiveDto;
import com.heima.media.entity.WmSensitive;
import com.heima.media.mapper.WmSensitiveMapper;
import com.heima.media.service.IWmSensitiveService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
 * <p>
 * 敏感词信息表 服务实现类
 * </p>
 *
 * @author mcm
 * @since 2022-06-21
 */
@Service
public class WmSensitiveServiceImpl extends ServiceImpl<WmSensitiveMapper, WmSensitive> implements IWmSensitiveService {

    /**
     * 敏感词列表查询
     * @param wmSensitiveDto
     * @return
     */
    @Override
    public ResponseResult listBy(WmSensitiveDto wmSensitiveDto) {
        Page<WmSensitive> page = new Page<>(wmSensitiveDto.getPage(), wmSensitiveDto.getSize());
        LambdaQueryWrapper<WmSensitive> query = new LambdaQueryWrapper<>();
        if (!StringUtils.isEmpty(wmSensitiveDto.getName())){
            query.like(WmSensitive::getSensitives,wmSensitiveDto.getName());
        }
        Page<WmSensitive> wmSensitivePage = this.page(page, query);
        long total = wmSensitivePage.getTotal();
        List<WmSensitive> records = wmSensitivePage.getRecords();
        PageResponseResult result=new PageResponseResult(wmSensitiveDto.getPage(),wmSensitiveDto.getSize(),total,records);

        return result;
    }
}
